/*****************/
function stopBubble(e) {
    // 如果传入了事件对象，那么就是非ie浏览器  
    if (e && e.stopPropagation) {
        //因此它支持W3C的stopPropagation()方法  
        e.stopPropagation();
    } else {
        //否则我们使用ie的方法来取消事件冒泡  
        window.event.cancelBubble = true;
    }
}

var tap = 'ontouchstart' in document ? 'touchend' : 'click';
var winWt = parseInt($(window).width()),
    winHt = parseInt($(window).height());

//实现滚动条无法滚动
var winHadntScroll = function(e) {
    e.preventDefault();
};

/***禁止滑动***/
function scrollStop() {
    var h = $(window).height();
    document.body.style.overflow = 'hidden';
    document.addEventListener("touchmove", winHadntScroll, { passive: false }); //禁止页面滑动
}

/***取消滑动限制***/
function scrollMove() {
    document.body.style.overflow = ''; //出现滚动条
    document.removeEventListener("touchmove", winHadntScroll, { passive: false });
}

/// 锚点跳转
function anchorMove(id, fn) {
    var $obj = $(id),
        moveFun = fn;
    var oh = $obj.offset().top - parseInt($('.header').outerHeight());
    $('html,body').animate({
        scrollTop: oh
    }, 300, function() {
        if (moveFun) moveFun();
    });
};

/// 竖向滚动条
if ($('.scrollbox').length > 0) {
    $('.scrollbox').mCustomScrollbar({
        scrollInertia: 1000,
        advanced: {
            updateOnContentResize: true
        }
    });
}
/// 横向滚动条
if ($('.scrollbox2').length > 0) {
    $('.scrollbox2').mCustomScrollbar({
        axis: "x",
        mouseWheel: true,
        advanced: {
            updateOnContentResize: true
        }
    });
}

// 页面滚动wow.js再ie9以上引用
var wow = new WOW({
    boxClass: 'wow',
    animateClass: 'animated',
    offset: 100,
    mobile: true,
    live: true
});
if (!(/msie [6|7|8|9]/i.test(navigator.userAgent))) {
    wow.init();
};

// 模态框
$('.modal').on('shown.bs.modal', function() {
    $('body').addClass('modal-open');
});
$('.modal').on('hidden.bs.modal', function() {
    if ($(this).find('video').length) {
        var videoId = $(this).find('.video-js').attr('id');
        var myplayer = videojs(videoId);
        myplayer.pause();
        myplayer.currentTime(0);
    }
});
$('.modal-close').off(tap).on(tap, function() {
    var $modal = $(this).parents('.modal');
    $modal.modal('hide');
});

// 判断设备
var os = function() {
    var ua = navigator.userAgent,
        isWindowsPhone = /(?:Windows Phone)/.test(ua),
        isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone,
        isAndroid = /(?:Android)/.test(ua),
        isIOS = !!ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
        isFireFox = /(?:Firefox)/.test(ua),
        isChrome = /(?:Chrome|CriOS)/.test(ua),
        isTablet = /(?:iPad|PlayBook)/.test(ua) || (isAndroid && !/(?:Mobile)/.test(ua)) || (isFireFox && /(?:Tablet)/.test(ua)),
        isPhone = /(?:iPhone)/.test(ua) && !isTablet,
        isPc = !isPhone && !isAndroid && !isSymbian;
    return {
        isTablet: isTablet,
        isPhone: isPhone,
        isAndroid: isAndroid,
        isIOS: isIOS,
        isPc: isPc
    };
}();

// 判断是否微信
function is_weixin() {
    var ua = navigator.userAgent.toLowerCase();
    if (ua.match(/MicroMessenger/i) == "micromessenger") {
        return true;
    } else {
        return false;
    }
}

if (!os.isPc) {
    $('body').addClass('is-iphone');
} else {
    $('body').addClass('is-pc');
}
if (os.isAndroid) {
    $('body').addClass('is-android');
}
if (os.isIOS) {
    $('body').addClass('is-ios');
}

if (is_weixin()) {
    $('body').addClass('is-wx');
} else {
    $('body').addClass('not-wx');
}

// 单选框
$('.check-list label').on(tap, function() {
    $(this).parent('li').addClass('is-checked').siblings().removeClass('is-checked');
});

// 视频
$('.btn-open_video').on(tap, function() {
    $('.modal-video').modal('show');
});

$('[data-toggle="tab"]').on(tap, function() {
    var id = $(this).attr('href'),
        $lis = $(this).parent('li');
    $(this).tab('show');
    $lis.addClass('active').siblings().removeClass('active');
});



/******************************/

/*** 公共 ****/

// 底部技术支持
if ($('.foot-jszc_swip').length) {
    var footJsSwip = new Swiper('.foot-jszc_swip', {
        direction: 'vertical',
        autoplay: {
            delay: 1000,
            disableOnInteraction: false,
        },
        loop: true,
        observer: true,
        observeParents: true,
    });
}